﻿////const signalrConnection = new signalR.HubConnectionBuilder().withUrl(localStorage.getItem('hosttingaddr') + "/signalHub").build();
////signalrConnection.start().catch(err => console.error(err.toString()));
////signalrConnection.on("ReceiveMessage", function (data) {
////    if (data != null && data != "") {
////        var obj = JSON.parse(data);
////        if (obj != null && obj.menus != null) {
////            var menus = JSON.parse(obj.menus);
////            loadMenu(obj.menus);
////        }
////    }
////});

function getAhtml(obj) {
    var dir = obj.directory.replace(/\\/g, '%5C');
    if (obj.href != null && obj.href != "") {
        return "<a href=\"javascript: void (0); \" style=\"color:#fff\"  onclick=\"addTabContent('" + obj.name + "','" + obj.code + "','" + obj.href + dir + "')\"><i class=\"" + obj.img + "\"></i><cite title=\"" + obj.nameTitle + "\">" + obj.nameDesc + "</cite></a>";
    }
    else {
        return "<a href=\"javascript:void(0);\" style=\"color:#fff\"><i class=\"" + obj.img + "\"></i><cite title=\"" + obj.nameTitle + "\">" + obj.nameDesc + "</cite></a>"
    }

}
function loadMenu(res) {
    var html = "";
    if (res.length > 0) {
        for (var i = 0; i < res.length; i++) {
            //var strli = "<li class=\"layui-nav-item lay-unselect \" >";
            var strli = "<li class=\"layui-nav-item\" >";
            //加载第一级菜单；
            strli = strli + "<a href=\"javascript:void(0);\"><i class=\"" + res[i].img + "\"></i><cite title=\"" + res[i].nameTitle + "\">" + res[i].nameDesc + "</cite></a>";

            var twoChild = res[i].childMenus;
            if (twoChild.length > 0) {
                strli = strli + "<dl class=\"layui-nav-child\">";
                for (var j = 0; j < twoChild.length; j++) {
                    strli = strli + "<dd>" + getAhtml(twoChild[j]);
                    var threeChild = twoChild[j].childMenus;
                    if (threeChild != null && threeChild.length > 0) {
                        strli = strli + "<dl class=\"layui-nav-child\">"
                        for (var n = 0; n < threeChild.length; n++) {
                            strli = strli + "<dd>" + getAhtml(threeChild[n]) + "</dd>";
                        }
                        strli = strli + "</dl>";
                    }
                    strli = strli + "</dd > ";
                }
                strli = strli + "</dl>";
            }
            strli = strli + "</li>";
            html = html + strli;
        }
        layui.jquery("#menus").html(html);
    }
}